<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数值和字符串转换</title>
    <script type="text/javascript">
        var name = '谭金林'
        var age = 22
        alert(name + '的年龄为' + age)
        var a = '18'
        var b = '20'
        alert(a + b)
        // 隐式转换 数值转字符串
        var num = 20
        var myStr = num + ''
        alert(typeof myStr)
        // 字符串转数值
        var myNum = Number(myStr)
        alert(typeof myNum)
        // 字符串转数字
        var myStr1 = num.toString()
        alert(typeof myStr1)

        // 含字母转数值
        var n = '123a'
        var Num_n = Number(n)
        alert(Num_n)  // NaN Not a number
    </script>
</head>
<body>
    
</body>
</html>